package com.yby6.framework.context;

import com.yby6.system.domain.SysLog;
import lombok.Data;

/**
 * @program: yangbuyi-rbac
 * @ClassName: SystemContext
 * @create: 2021-05-12 14:23
 * @author: yangshuai
 * @since： JDK1.8
 * @SystemContext: $本地线程上下文 用来存储在同一个线程中可能会用到的全局变量
 **/
@Data
public class SystemContext {

    /**
     * 日志实体
     */
    private SysLog sysLog = new SysLog();

    /**
     * 是否记录日志
     */
    private boolean isLog = false;

    /**
     * 序列化类型
     */
    private boolean redisType = false;

    /**
     * 线程本地内存中的变量
     */
    private static ThreadLocal<SystemContext> threadLocal = new ThreadLocal<>();

    public static SystemContext get () {
        if (threadLocal.get() == null) {
            SystemContext threadLocalContext = new SystemContext();
            threadLocal.set(threadLocalContext);
        }
        return threadLocal.get();
    }

    public static void remove () {
        threadLocal.remove();
    }

}
